package collection;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

public class ArrayListDemo {
    public static void main(String[] args) {
        // build
        Double[] array = new Double[10];
        Random rand = new Random();
        for (int i = 0; i < 10; i++) {
            array[i] = rand.nextDouble();
        }
        List<Double> list = new ArrayList<Double>();
        list.addAll(Arrays.asList(array));
        Double e = rand.nextDouble();
        list.add(5, e);
        // browse
        System.out.println(list);
        // search
        System.out.println(list.get(3));
        System.out.println(list.indexOf(e));
        System.out.println(list.lastIndexOf(e));
        System.out.println(list.subList(3, 8));
        // update
        System.out.println(list.remove(3));
        System.out.println(list.set(0, rand.nextDouble()));
    }
}
